package tutorial.main.vista;

import tutorial.main.R;
import tutorial.main.data.GestorBDLista;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class DetalleEvento extends Activity
{

	Button btnVolver;
	Button btnEliminar;
	TextView txtDetalle;
	private static final int id_dialogo_eliminar_evento=1;
	Activity yo=this;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detalle_evento);
		
		
		btnVolver = (Button)this.findViewById(R.id.BotonDetalleVolver);
		btnEliminar=(Button)this.findViewById(R.id.BotonEliminarEvento);
		txtDetalle = (TextView)this.findViewById(R.id.TxtDetalle);
		
		String buffer = "";
		
		buffer += getIntent().getExtras().getString("evento_estado");
		buffer += "\n";
		buffer += getIntent().getExtras().getString("evento_tipo");
		buffer += "\n";
		buffer += getIntent().getExtras().getString("evento_subtipo");
		buffer += "\n";
		buffer += getIntent().getExtras().getString("evento_reason");
		buffer += "\n";						
		buffer += getIntent().getExtras().getString("evento_fecha");
		buffer += "\n";
		buffer += getIntent().getExtras().getString("evento_sync");
		
		txtDetalle.setText(buffer);
		
		this.btnVolver.setOnClickListener(new OnClickListener() 
		{
			public void onClick(View arg0) 
			{
				DetalleEvento.this.finish();
			}
		});
		
		this.btnEliminar.setOnClickListener(new OnClickListener() 
		{
			
			public void onClick(View arg0) 
			{
				
				/*System.out.println("ELIMINAR EVENTO:"+getIntent().getExtras().getInt("evento_id"));
				GestorBDLista.deleteEvento(yo,  getIntent().getExtras().getInt("evento_id"));
				//GestorBDLista.deleteEvento(getContentResolver(),  getIntent().getExtras().getInt("evento_id"));
				DetalleEvento.this.finish();*/
				showDialog(id_dialogo_eliminar_evento);
			}
		});		
		
	}
	
	//Creacion de dialogos segun su tipo
	@Override
    protected Dialog onCreateDialog(int id)
    {
    	Dialog dialogo= null;
    	switch(id) {
        case id_dialogo_eliminar_evento:
            dialogo=crearDialogoEliminarEvento();
            break;       
        
        default:
            dialogo = null;
        }

    	return dialogo;
    }
	
	//Creacion confirmacion de eliminacion
    private Dialog crearDialogoEliminarEvento()
    {
    	AlertDialog.Builder builder = new AlertDialog.Builder(yo);
    	builder.setMessage(getString(R.string.msje_confirmarEliminarEventoUnico));
    	builder.setPositiveButton(R.string.si, new DialogInterface.OnClickListener() {
    	           public void onClick(DialogInterface dialog, int id) 
    	           {
    	        	   System.out.println("ELIMINAR EVENTO:"+getIntent().getExtras().getInt("evento_id"));
    					GestorBDLista.deleteEvento(yo,  getIntent().getExtras().getInt("evento_id"));
    					//GestorBDLista.deleteEvento(getContentResolver(),  getIntent().getExtras().getInt("evento_id"));
    					DetalleEvento.this.finish();
    	           }
    	       });
    	builder.setNegativeButton(R.string.no, null);
    	AlertDialog dialogoEliminarEventos = builder.create();
    	dialogoEliminarEventos .setTitle(getString(R.string.f_menu_eliminar));
    	return dialogoEliminarEventos;
    }
}
